import { createBrowserRouter } from "react-router-dom";
import HomePage from "../pages/HomePage";
import ProfilePage from "../pages/ProfilePage";
import Layout from "../components/layout";
import ErrorPage from "../pages/ErrorPage";
import AuthPage from "../pages/AuthPage";
import AuthRouter from "../components/AuthRouter";
import StudentList, { loader as studentListLoader, action as studentListAction } from "../components/student/StudentList";
import Student,{loader as studentLoader} from "../components/student/Student";
import { action as destoryAction } from "../components/student/destorey";
// import {action as authAction} from '../components/AuthForm'
// 调用createBrowserRouter()创建router
const router = createBrowserRouter([
    {
        //根组件->根路由
        path: '/',
        element: <Layout />,
        errorElement: <ErrorPage />,
        children: [
            {
                index: true,
                element: <HomePage />
            },
            {//通过高阶组件AuthRouter对路由进行鉴权，登陆了才能访问/profile路由
                path: '/profile',
                element: <AuthRouter>
                    <ProfilePage />
                </AuthRouter>


            },
            {
                path: '/authForm',
                element: <AuthPage />,
                // action:authAction

            },
            {
                path: '/studentList',
                element: <AuthRouter>
                    <StudentList />
                </AuthRouter>,
                loader: studentListLoader,
                action: studentListAction,
                children: [
                    {
                        path: 'students/:id',
                        element: <Student />,
                        loader:studentLoader
                    },{
                        path:'students/:id/destory',
                        action:destoryAction
                    }
                ]

            }
        ]


    },

])
export default router